/**
 * hook-fetch 相关类型定义
 */

// 通用对象类型
export interface IObject<T = any> {
  [key: string]: T;
}

// HTTP响应接口
export interface IHttpResponse<T = any> {
  code: number;
  data: T;
  msg: string;
  success?: boolean;
  total?: number;
  rows?: T[];
}

// 请求配置接口
export interface IRequestConfig {
  url: string;
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
  params?: IObject;
  body?: any;
  headers?: IObject;
  timeout?: number;
}

// 分页请求参数
export interface IPaginationParams {
  page?: number;
  pageSize?: number;
  current?: number;
  size?: number;
}

// 分页响应数据
export interface IPaginationResponse<T = any> {
  list: T[];
  total: number;
  page: number;
  pageSize: number;
  pages?: number;
}

// 文件上传进度回调
export type UploadProgressCallback = (progress: number) => void;

// 下载配置
export interface IDownloadConfig {
  url: string;
  filename?: string;
  method?: 'GET' | 'POST';
  params?: IObject;
  headers?: IObject;
}

// 上传配置
export interface IUploadConfig {
  url: string;
  file: File | FormData;
  onProgress?: UploadProgressCallback;
  headers?: IObject;
}

// 错误响应接口
export interface IErrorResponse {
  code: number;
  msg: string;
  data?: any;
}

// 请求拦截器配置
export interface IInterceptorConfig {
  enableAuth?: boolean;
  enableDeduplication?: boolean;
  enableErrorHandler?: boolean;
  tokenKey?: string;
  authHeaderName?: string;
}

// 缓存配置
export interface ICacheConfig {
  enable?: boolean;
  maxAge?: number;
  maxSize?: number;
  keyGenerator?: (config: IRequestConfig) => string;
}

// 重试配置
export interface IRetryConfig {
  enable?: boolean;
  maxRetries?: number;
  retryDelay?: number;
  retryCondition?: (error: any) => boolean;
}

// hook-fetch 实例配置
export interface IHookFetchConfig {
  baseURL?: string;
  timeout?: number;
  headers?: IObject;
  interceptors?: IInterceptorConfig;
  cache?: ICacheConfig;
  retry?: IRetryConfig;
}

// 导出所有类型
export type {
  IObject,
  IHttpResponse,
  IRequestConfig,
  IPaginationParams,
  IPaginationResponse,
  UploadProgressCallback,
  IDownloadConfig,
  IUploadConfig,
  IErrorResponse,
  IInterceptorConfig,
  ICacheConfig,
  IRetryConfig,
  IHookFetchConfig,
};